﻿CREATE PROCEDURE [dbo].[proc_ProjectExpenditure_Create]
	(
		@PEId uniqueidentifier,
		@ProjectName nvarchar(50),
		@Content text,
		@ApplyAmount numeric(18,2),
		@SubjectId int,
		@LaunchDate datetime,
		@Description text,
		@DepartmentId int,
		@UserName nvarchar(50),
		@CompanyId int
	)
AS
	--Declare @CompanyId int
	--Set @CompanyId = (select Companyid from aspnet_Users where username=@UserName)
	
	Insert Into ProjectExpenditure
	(
		PEId,
		ProjectName,
		DepartmentId,
		UserName,
		Content,
		ApplyAmount,
		SubjectId,
		LaunchDate,
		Description,
		CompanyId
	)
	Values
	(
		@PEId,
		@ProjectName,
		@DepartmentId,
		@UserName,
		@Content,
		@ApplyAmount,
		@SubjectId,
		@LaunchDate,
		@Description,
		@CompanyId
	)
	
	--将临时表中的记录填到明细表ProjectExpenditure_Item中 1.10加
	INSERT INTO [ProjectExpenditure_Item]
           ([PEItemId]
           ,[PEId]
           ,[PayItem]
           ,[ComeInUnit]
           ,[PlanPayDate]
           ,[Moneydues]
           ,[PracticalPayDate]
           ,[PayAmount]
           ,[ComeInPerson]
           ,[ComeInDate])
     SELECT 
           peit.PEItemId
           ,@PEId
           ,peit.PayItem
           ,peit.ComeInUnit
           ,peit.PlanPayDate
           ,peit.Moneydues
           ,peit.PracticalPayDate
           ,peit.PayAmount
           ,peit.ComeInPerson
           ,peit.ComeInDate
	
     FROM ProjectExpenditure_ItemTemp as peit WHERE peit.PEId=@UserName
	
	--删除临时表中的记录 1.10加
	DELETE FROM ProjectExpenditure_ItemTemp WHERE PEId=@UserName
	
	RETURN
